% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
  letterpaper,
  DIV=11,
  numbers=noendperiod]{scrreprt}

\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else  
    % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{5}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}

\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother

\KOMAoption{captions}{tableheading}
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
  \renewcommand*\contentsname{Table of contents}
\else
  \newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
  \renewcommand*\listfigurename{List of Figures}
\else
  \newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
  \renewcommand*\listtablename{List of Tables}
\else
  \newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
  \renewcommand*\figurename{Figure}
\else
  \newcommand\figurename{Figure}
\fi
\ifdefined\tablename
  \renewcommand*\tablename{Table}
\else
  \newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\makeatother
\makeatletter
\@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\makeatother
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
  pdftitle={R语言从入门到精通},
  pdfauthor={心有灵犀R(B站)},
  colorlinks=true,
  linkcolor={blue},
  filecolor={Maroon},
  citecolor={Blue},
  urlcolor={Blue},
  pdfcreator={LaTeX via pandoc}}

\title{R语言从入门到精通}
\author{心有灵犀R(B站)}
\date{}

\begin{document}
\maketitle
\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[sharp corners, enhanced, interior hidden, breakable, borderline west={3pt}{0pt}{shadecolor}, boxrule=0pt, frame hidden]}{\end{tcolorbox}}\fi

\renewcommand*\contentsname{Table of contents}
{
\hypersetup{linkcolor=}
\setcounter{tocdepth}{2}
\tableofcontents
}
\bookmarksetup{startatroot}

\hypertarget{ux7b80ux4ecb}{%
\chapter{简介}\label{ux7b80ux4ecb}}

R语言从入门到精通，涵盖R基础，tidyverse系列内容和一些R语言进阶方面的内容，包括不仅限于R包创建，shiny搭建网站，rmarkdown书写报告；mlr3verse做机器学习，targets包R语言工作流；

\includegraphics{images/1724746580732.jpg}

\part{R语言基础}

本章汇总一些R语言常用的基础知识。

\hypertarget{rux8bedux8a00ux548crstudioux5b89ux88c5}{%
\chapter{R语言和Rstudio安装}\label{rux8bedux8a00ux548crstudioux5b89ux88c5}}

\hypertarget{ux5b89ux88c5r}{%
\section{安装R}\label{ux5b89ux88c5r}}

下载链接：\url{https://mirrors.tuna.tsinghua.edu.cn/CRAN/}

选择合适的版本下载，下载R和Rtools。（R和Rtools的版本要一致）

\begin{figure}

{\centering \includegraphics{chapter/R语言基础/images/1724747247314.jpg}

}

\end{figure}

下载后，默认参数直接下一步下一步安装就好，（安装路径不要有中文，空格，特殊字符）。

安装之后张这样。

\hypertarget{ux5b89ux88c5rstudio}{%
\section{安装Rstudio}\label{ux5b89ux88c5rstudio}}

使用Rstudio编写和运行R代码。

下载地址：\url{https://www.rstudio.com/products/rstudio/download}

直接下一步下一步安装就好，一定要先安装R，再安装RStudio。

\hypertarget{ux754cux9762ux4ecbux7ecd}{%
\subsection{界面介绍}\label{ux754cux9762ux4ecbux7ecd}}

Rstudio基本的界面介绍

\hypertarget{ux5fc5ux8981ux64cdux4f5c}{%
\section{必要操作}\label{ux5fc5ux8981ux64cdux4f5c}}

RStudio上方导航栏，Tools-\textgreater Global
Options，里面的保存文件的编码设置为''UTF-8''，否则代码可能会出现中文乱码的问题。

\includegraphics[width=6.78125in,height=\textheight]{chapter/R语言基础/images/1724747378389.jpg}

安装包时把下载链接设成国内，否则可能下载过慢。

\includegraphics[width=6.8125in,height=\textheight]{chapter/R语言基础/images/1724747392046.jpg}

\hypertarget{ux7b2cux4e00ux4e2arux8bedux8a00ux7a0bux5e8f}{%
\section{第一个R语言程序}\label{ux7b2cux4e00ux4e2arux8bedux8a00ux7a0bux5e8f}}

在左上角写代码，之后运行，运行过程和结果会展示在左下角区域，并把a和b变量的信息存储到当前环境中，可以在''Environment''中查看。

\includegraphics{chapter/R语言基础/images/1724747425172.jpg}

\hypertarget{ux88c5ux5305ux65b9ux5f0fux603bux7ed3}{%
\chapter{装包方式总结}\label{ux88c5ux5305ux65b9ux5f0fux603bux7ed3}}

\hypertarget{ux666eux901aux5b89ux88c5ux4ececranux5b89ux88c5}{%
\section{\texorpdfstring{\textbf{普通安装(从CRAN安装)}}{普通安装(从CRAN安装)}}\label{ux666eux901aux5b89ux88c5ux4ececranux5b89ux88c5}}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"包名"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\hypertarget{ux4ecebioconductorux5b89ux88c5ux4e3bux8981ux662fux4e00ux4e9bux751fux7269ux5b66ux5305}{%
\section{\texorpdfstring{\textbf{从Bioconductor安装（主要是一些生物学包）}}{从Bioconductor安装（主要是一些生物学包）}}\label{ux4ecebioconductorux5b89ux88c5ux4e3bux8981ux662fux4e00ux4e9bux751fux7269ux5b66ux5305}}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# 先安装BiocManager包}
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"BiocManager"}\NormalTok{)}
\CommentTok{\# 再调用BiocManager包里的install函数安装}
\NormalTok{BiocManager}\SpecialCharTok{::}\FunctionTok{install}\NormalTok{(}\StringTok{"包名"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\hypertarget{ux4ecegithubux4e0aux5b89ux88c5}{%
\section{\texorpdfstring{\textbf{从GitHub上安装}}{从GitHub上安装}}\label{ux4ecegithubux4e0aux5b89ux88c5}}

\hypertarget{ux65b9ux5f0fux4e00-devtools}{%
\subsection{\texorpdfstring{\textbf{方式一：
devtools}}{方式一： devtools}}\label{ux65b9ux5f0fux4e00-devtools}}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# 先安装devtools包}
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)}
\CommentTok{\# 再调用devtools包里的install\_github函数安装}
\NormalTok{devtools}\SpecialCharTok{::}\FunctionTok{install\_github}\NormalTok{(}\StringTok{"github用户名/包名"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\hypertarget{ux65b9ux5f0fux4e8c-remotes}{%
\subsection{\texorpdfstring{\textbf{方式二：
remotes}}{方式二： remotes}}\label{ux65b9ux5f0fux4e8c-remotes}}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# 先安装remotes包}
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"remotes"}\NormalTok{)}
\CommentTok{\# 再调用remotes包里的install\_github函数安装}
\NormalTok{remotes}\SpecialCharTok{::}\FunctionTok{install\_gitlab}\NormalTok{(}\StringTok{"github用户名/包名"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\hypertarget{ux4e0bux8f7dux5230ux672cux5730ux5b89ux88c5}{%
\section{\texorpdfstring{\textbf{下载到本地安装}}{下载到本地安装}}\label{ux4e0bux8f7dux5230ux672cux5730ux5b89ux88c5}}

\hypertarget{cran}{%
\subsection{\texorpdfstring{\textbf{CRAN}}{CRAN}}\label{cran}}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  从\href{https://link.zhihu.com/?target=https\%3A//cran.r-project.org/web/packages/available_packages_by_name.html}{https://cran.r-project.org/web/packages/available\_packages\_by\_name.html}中找到并下载R包到本地
\item
  install.packages(``路径+文件名称'')
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"C://Users/82414/Downloads/ggplot2\_3.3.5.tar.gz"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\textbf{注意}：还需要按照CRAN上的提示安装此包的依赖包

\hypertarget{bioconductor}{%
\subsection{Bioconductor}\label{bioconductor}}

从\url{http://bioconductor.org/packages/release/BiocViews.html\#___Software}中找到并下载R包到本地

上述方法

\hypertarget{github}{%
\subsection{\texorpdfstring{\textbf{GitHub}}{GitHub}}\label{github}}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  从\href{https://link.zhihu.com/?target=https\%3A//github.com/}{https://github.com/}上找到并下载
\item
  解压并在R中打开此路径（setwd(``路径名'')）
\item
  安装
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{devtools}\SpecialCharTok{::}\FunctionTok{install\_local}\NormalTok{()}
\end{Highlighting}
\end{Shaded}

\hypertarget{condaux5b89ux88c5}{%
\section{\texorpdfstring{\textbf{conda安装}}{conda安装}}\label{condaux5b89ux88c5}}

如果使用了conda环境，可以用conda的功能安装R包，还会自动的安装所需要的lib环境，相当省心。

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{conda install r}\SpecialCharTok{{-}}\NormalTok{包名}
\end{Highlighting}
\end{Shaded}

\hypertarget{ux5e38ux89c1ux95eeux9898ux603bux7ed3}{%
\section{\texorpdfstring{\textbf{常见问题总结}}{常见问题总结}}\label{ux5e38ux89c1ux95eeux9898ux603bux7ed3}}

\hypertarget{package-name-is-not-available-for-this-version-of-r}{%
\subsection{\texorpdfstring{\textbf{package `name' is not available for
this version of
R}}{package `name' is not available for this version of R}}\label{package-name-is-not-available-for-this-version-of-r}}

Warning in install.packages : package `Mfuzz' is not available for this
version of R

\begin{itemize}
\item
  可能是包的名字写错了
\item
  通常情况下，一般是需要用到本文中第2或3种方法安装
\item
  从CRAN上检查此包需要的R版本，如果大于您的R版本，需要升级R
\end{itemize}

\hypertarget{ux4f9dux8d56ux5305ux6ca1ux6709ux88c5ux4e0a}{%
\subsection{依赖包没有装上}\label{ux4f9dux8d56ux5305ux6ca1ux6709ux88c5ux4e0a}}

\begin{itemize}
\tightlist
\item
  去安装报错的依赖包，再去安装想要的那个包
\end{itemize}

\hypertarget{need-r-4.1.2but-your-r-is-3.6.3}{%
\subsection{need R \textgreater{} 4.1.2，but your R is
3.6.3}\label{need-r-4.1.2but-your-r-is-3.6.3}}

\begin{itemize}
\item
  需要升级R
\item
  当然也可以强制安装
\end{itemize}

\hypertarget{ux7f3aux5c11rjava}{%
\subsection{缺少rjava}\label{ux7f3aux5c11rjava}}

受到R语言实战那本书的影响，xlsx包需要rjava环境，强烈建议弃用xlsx包，换用readxl包

\hypertarget{ux9644ux5f55}{%
\section{\texorpdfstring{\textbf{附录}}{附录}}\label{ux9644ux5f55}}

\begin{itemize}
\tightlist
\item
  CRAN有哪些包：
\end{itemize}

\href{https://link.zhihu.com/?target=https\%3A//cran.r-project.org/web/packages/available_packages_by_name.html}{\textbf{https://cran.r-project.org/web/packages/available\_packages\_by\_name.html}\hspace{0pt}cran.r-project.org/web/packages/available\_packages\_by\_name.html}

\begin{itemize}
\tightlist
\item
  Bioconductor有哪些包：
\end{itemize}

\href{https://link.zhihu.com/?target=http\%3A//bioconductor.org/packages/release/BiocViews.html\%23___Software}{\textbf{Bioconductor
-
BiocViews}\hspace{0pt}bioconductor.org/packages/release/BiocViews.html\#\_\_\_Software}

\begin{itemize}
\tightlist
\item
  anaconda查包：
\end{itemize}

\href{https://link.zhihu.com/?target=https\%3A//anaconda.org/}{\textbf{https://anaconda.org/}\hspace{0pt}anaconda.org/}

\hypertarget{ux57faux672cux6570ux636eux7c7bux578b}{%
\chapter{基本数据类型}\label{ux57faux672cux6570ux636eux7c7bux578b}}

\hypertarget{ux57faux672cux6570ux636eux7c7bux578b-1}{%
\section{基本数据类型}\label{ux57faux672cux6570ux636eux7c7bux578b-1}}

\textbf{数值型}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{a }\OtherTok{=} \DecValTok{1}   
\end{Highlighting}
\end{Shaded}

字符型，双引号括起来

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{b }\OtherTok{=} \StringTok{"hi"} 
\end{Highlighting}
\end{Shaded}

逻辑型，TRUE和FALSE，可以缩写成T或者F

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{c }\OtherTok{=} \ConstantTok{TRUE} 
\end{Highlighting}
\end{Shaded}

\hypertarget{ux67e5ux770bux7c7bux578b}{%
\section{查看类型}\label{ux67e5ux770bux7c7bux578b}}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{class}\NormalTok{(a)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] "numeric"
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{class}\NormalTok{(b)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] "character"
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{class}\NormalTok{(c)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] "logical"
\end{verbatim}

\hypertarget{ux5224ux65adux7c7bux578bux4e0eux8f6cux6362ux7c7bux578b}{%
\section{\texorpdfstring{判断类型与转换类型\r



:::}{判断类型与转换类型::}}\label{ux5224ux65adux7c7bux578bux4e0eux8f6cux6362ux7c7bux578b}}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{is.numeric}\NormalTok{(}\StringTok{"1"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] FALSE
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{as.numeric}\NormalTok{(}\StringTok{"1"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] 1
\end{verbatim}

:::

\hypertarget{ux57faux672cux8fd0ux7b97ux7b26}{%
\section{\texorpdfstring{基本运算符\r}{基本运算符}}\label{ux57faux672cux8fd0ux7b97ux7b26}}

\hypertarget{ux6570ux5b66ux8fd0ux7b97}{%
\subsection{数学运算}\label{ux6570ux5b66ux8fd0ux7b97}}

``+ - * / \^{}''

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{1} \SpecialCharTok{+} \DecValTok{2}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] 3
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{1} \SpecialCharTok{+} \StringTok{"1"}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
Error in 1 + "1": 二进列运算符中有非数值参数
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{2} \SpecialCharTok{+} \ConstantTok{TRUE}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] 3
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{2} \SpecialCharTok{+} \ConstantTok{FALSE}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] 2
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{2} \SpecialCharTok{+} \StringTok{"TRUE"}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
Error in 2 + "TRUE": 二进列运算符中有非数值参数
\end{verbatim}

\hypertarget{ux6bd4ux8f83ux8fd0ux7b97}{%
\subsection{比较运算}\label{ux6bd4ux8f83ux8fd0ux7b97}}

``\textgreater{} \textless{} \textgreater= \textless= == !=''

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{1} \SpecialCharTok{\textgreater{}} \DecValTok{2}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] FALSE
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{1} \SpecialCharTok{==} \DecValTok{2}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] FALSE
\end{verbatim}

\hypertarget{ux903bux8f91ux8fd0ux7b97ux7b26}{%
\subsection{\texorpdfstring{逻辑运算符\r}{逻辑运算符}}\label{ux903bux8f91ux8fd0ux7b97ux7b26}}

\& \textbar{}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{T }\SpecialCharTok{\&}\NormalTok{ F}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] FALSE
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{T }\SpecialCharTok{|}\NormalTok{ F}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] TRUE
\end{verbatim}

\hypertarget{ux5c0fux7ed3}{%
\subsection{小结}\label{ux5c0fux7ed3}}

数学运算法返回的是结果是数值型；比较和逻辑运算返回的是结果是逻辑型\r

\hypertarget{ux7f3aux5931ux503c-na-ux7f3aux5931ux503c-nan-ux975eux6570}{%
\section{\texorpdfstring{缺失值\r

- NA 缺失值\r

- NaN
非数}{缺失值 NA 缺失值 NaN 非数}}\label{ux7f3aux5931ux503c-na-ux7f3aux5931ux503c-nan-ux975eux6570}}

\begin{itemize}
\item
  NULL 空\r
\item
  Inf 无穷大\r
\item
  NA具有传染性，NA参与的运算，就够会变成NA
\end{itemize}

\begin{Shaded}
\begin{Highlighting}[]
\DecValTok{1} \SpecialCharTok{+} \ConstantTok{NA}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] NA
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{is.na}\NormalTok{(}\ConstantTok{NA}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
[1] TRUE
\end{verbatim}



\end{document}
